package org.yiqixue.accounts.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.yiqixue.accounts.entity.Transaction;
import org.yiqixue.accounts.entity.TransactionType;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 交易数据访问接口
 */
public interface TransactionRepository extends JpaRepository<Transaction, Long> {
    
    /**
     * 根据手机号和交易类型查询当日交易记录
     * @param phoneNumber 手机号
     * @param type 交易类型
     * @param startOfDay 当日开始时间
     * @param endOfDay 当日结束时间
     * @return 交易记录列表
     */
    @Query("SELECT t FROM Transaction t WHERE t.account.phoneNumber = :phoneNumber " +
           "AND t.type = :type AND t.transactionDate BETWEEN :startOfDay AND :endOfDay")
    List<Transaction> findByPhoneNumberAndTypeAndDate(
            @Param("phoneNumber") String phoneNumber,
            @Param("type") TransactionType type,
            @Param("startOfDay") LocalDateTime startOfDay,
            @Param("endOfDay") LocalDateTime endOfDay);
} 